package com.clwl.supervise.superviseapp.service.notice;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clwl.supervise.superviseapp.entity.supervise.JgNotice;
import com.clwl.supervise.superviseapp.mapper.supervise.JgNoticeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class JgNoticeService {
   @Autowired
    JgNoticeMapper jgNoticeMapper;
   public Map<String,Object> getNoticeByType(Integer pageNum, Integer pageSize, Long noticeType){
       Map<String,Object> resultMap=new HashMap<>();
       Page<Map<String, Object>> iPage = Page.of(pageNum, pageSize);
       iPage.setOptimizeCountSql(false);
       iPage.setSearchCount(false);
       IPage<JgNotice> pageList = jgNoticeMapper.selectNoticePageByTypeAndCarousel(iPage,noticeType,0L);
       List<JgNotice> carouselList=jgNoticeMapper.selectNoticeByTypeAndCarousel(noticeType,1L);
       if(CollectionUtils.isEmpty(carouselList)){
           carouselList=new ArrayList<>();
       }
       resultMap.put("carouselList",carouselList);
       resultMap.put("noticeList",pageList.getRecords());
       return resultMap;
    }

    public JgNotice getJgNoticeDetail(Long id){
        List<JgNotice> detailList=jgNoticeMapper.selectNoticeById(id);
        if(CollectionUtils.isEmpty(detailList)){
            return new JgNotice();
        }
       return detailList.get(0);
    }
}
